package p270jp.pxv.android.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import java.util.ArrayList;
import java.util.Iterator;
import p014ae.ViewTreeObserver$OnGlobalLayoutListenerC0200z5;
import p167g.C3149d;
import p325m0.MutabilityOwnership;
import p374nm.C5415v0;
import p375nn.C5420f;
import p436q6.StringMerger;
import p629xm.Iterators;
import p629xm.IteratorsJVM;
import p629xm._Collections;

/* compiled from: ZoomView.kt */
/* renamed from: jp.pxv.android.view.ZoomView */
/* loaded from: classes2.dex */
public final class ZoomView extends ConstraintLayout {

    /* renamed from: N */
    public static final /* synthetic */ int f19719N;

    /* renamed from: A */
    public float f19720A;

    /* renamed from: D */
    public float f19723D;

    /* renamed from: E */
    public float f19724E;

    /* renamed from: F */
    public float f19725F;

    /* renamed from: G */
    public float f19726G;

    /* renamed from: H */
    public boolean f19727H;

    /* renamed from: I */
    public GestureDetector f19728I;

    /* renamed from: J */
    public ScaleGestureDetector f19729J;

    /* renamed from: K */
    public View.OnClickListener f19730K;

    /* renamed from: L */
    public int f19731L;

    /* renamed from: M */
    public int f19732M;

    /* renamed from: x */
    public float f19738x;

    /* renamed from: y */
    public float f19739y;

    /* renamed from: z */
    public float f19740z;

    /* renamed from: s */
    public float f19733s = 1.0f;

    /* renamed from: t */
    public float f19734t = 1.0f;

    /* renamed from: u */
    public float f19735u = 5.0f;

    /* renamed from: v */
    public float f19736v = 1.0f;

    /* renamed from: w */
    public float f19737w = 2.0f;

    /* renamed from: B */
    public boolean f19721B = true;

    /* renamed from: C */
    public boolean f19722C = true;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ZoomView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        MutabilityOwnership.m3745m(context, "context");
        if (!isInEditMode()) {
            getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver$OnGlobalLayoutListenerC0200z5(this, 2));
            this.f19728I = new GestureDetector(context, new p374nm.ZoomView(this));
            this.f19729J = new ScaleGestureDetector(context, new C5415v0(this));
        }
    }

    /* renamed from: w */
    public static void m4452w(ZoomView zoomView, float f, float f2, float f3, int i) {
        if ((i & 2) != 0) {
            f2 = ((float) zoomView.getWidth()) / 2.0f;
        }
        if ((i & 4) != 0) {
            f3 = ((float) zoomView.getHeight()) / 2.0f;
        }
        float f4 = StringMerger.m2856f(f, zoomView.f19736v, zoomView.f19735u);
        zoomView.f19733s = f4;
        zoomView.f19738x = f2;
        zoomView.f19739y = f3;
        zoomView.m4453v(f4, f2, f3);
    }

    @Override // androidx.constraintlayout.widget.ConstraintLayout, android.view.ViewGroup, android.view.View
    public void dispatchDraw(Canvas canvas) {
        MutabilityOwnership.m3745m(canvas, "canvas");
        if (this.f19727H) {
            float width = ((float) getWidth()) / 2.0f;
            float height = ((float) getHeight()) / 2.0f;
            float f = this.f19734t;
            float f2 = ((width - ((width - this.f19723D) * f)) / f) + width;
            float f3 = width - ((width - ((this.f19724E - width) * f)) / f);
            float f4 = ((height - ((height - this.f19725F) * f)) / f) + height;
            float f5 = height - ((height - ((this.f19726G - height) * f)) / f);
            float min = Math.min(f2, f3);
            float max = Math.max(f2, f3);
            float min2 = Math.min(f4, f5);
            float max2 = Math.max(f4, f5);
            this.f19733s = m4455t(this.f19733s, this.f19734t);
            this.f19740z = StringMerger.m2856f(this.f19740z, min, max);
            this.f19720A = StringMerger.m2856f(this.f19720A, min2, max2);
            this.f19738x = m4455t(this.f19738x, this.f19740z);
            this.f19739y = m4455t(this.f19739y, this.f19720A);
            this.f19738x = StringMerger.m2856f(this.f19738x, min, max);
            this.f19739y = StringMerger.m2856f(this.f19739y, min2, max2);
            if (getChildCount() != 0) {
                boolean z = false;
                C5420f v = StringMerger.m2840v(0, getChildCount());
                ArrayList<View> arrayList = new ArrayList(IteratorsJVM.m703K(v, 10));
                Iterator<Integer> it = v.iterator();
                while (it.hasNext()) {
                    arrayList.add(getChildAt(((Iterators) it).mo677c()));
                }
                Matrix matrix = new Matrix();
                matrix.setTranslate(width, height);
                float f6 = this.f19733s;
                matrix.preScale(f6, f6);
                matrix.preTranslate(-this.f19738x, -this.f19739y);
                for (View view : arrayList) {
                    Matrix matrix2 = new Matrix();
                    matrix2.set(matrix);
                    matrix2.preTranslate((float) view.getLeft(), (float) view.getTop());
                    canvas.save();
                    canvas.concat(matrix2);
                    view.draw(canvas);
                    canvas.restore();
                }
                if (Math.abs(this.f19733s - this.f19734t) > 0.0f || Math.abs(this.f19738x - this.f19740z) > 0.0f || Math.abs(this.f19739y - this.f19720A) > 0.0f) {
                    z = true;
                }
                if (z) {
                    getRootView().invalidate();
                    invalidate();
                }
            }
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        MutabilityOwnership.m3745m(motionEvent, "event");
        if (motionEvent.getPointerCount() == 2) {
            ScaleGestureDetector scaleGestureDetector = this.f19729J;
            if (scaleGestureDetector != null) {
                scaleGestureDetector.onTouchEvent(motionEvent);
                motionEvent.setAction(3);
                super.dispatchTouchEvent(motionEvent);
            } else {
                MutabilityOwnership.m3737u("pinchGestureDetector");
                throw null;
            }
        }
        if (motionEvent.getPointerCount() == 1) {
            GestureDetector gestureDetector = this.f19728I;
            if (gestureDetector != null) {
                gestureDetector.onTouchEvent(motionEvent);
                float x = motionEvent.getX();
                float width = ((x - (((float) getWidth()) / 2.0f)) / this.f19733s) + this.f19738x;
                float y = motionEvent.getY();
                motionEvent.setLocation(width, ((y - (((float) getHeight()) / 2.0f)) / this.f19733s) + this.f19739y);
                super.dispatchTouchEvent(motionEvent);
            } else {
                MutabilityOwnership.m3737u("panGestureDetector");
                throw null;
            }
        }
        getRootView().invalidate();
        invalidate();
        return true;
    }

    public final float getTargetTransX() {
        return this.f19740z;
    }

    public final float getTargetTransY() {
        return this.f19720A;
    }

    public final float getTargetZoom() {
        return this.f19734t;
    }

    public final float getTransX() {
        return this.f19738x;
    }

    public final float getTransY() {
        return this.f19739y;
    }

    public final float getZoom() {
        return this.f19733s;
    }

    /* renamed from: s */
    public final void m4456s() {
        C5420f v = StringMerger.m2840v(0, getChildCount());
        ArrayList<View> arrayList = new ArrayList(IteratorsJVM.m703K(v, 10));
        Iterator<Integer> it = v.iterator();
        while (it.hasNext()) {
            arrayList.add(getChildAt(((Iterators) it).mo677c()));
        }
        ArrayList arrayList2 = new ArrayList(IteratorsJVM.m703K(arrayList, 10));
        for (View view : arrayList) {
            arrayList2.add(Integer.valueOf(view.getLeft()));
        }
        Comparable a0 = _Collections.m687a0(arrayList2);
        MutabilityOwnership.m3747j(a0);
        this.f19723D = (float) ((Number) a0).intValue();
        ArrayList arrayList3 = new ArrayList(IteratorsJVM.m703K(arrayList, 10));
        for (View view2 : arrayList) {
            arrayList3.add(Integer.valueOf(view2.getRight()));
        }
        Comparable Y = _Collections.m689Y(arrayList3);
        MutabilityOwnership.m3747j(Y);
        this.f19724E = (float) ((Number) Y).intValue();
        ArrayList arrayList4 = new ArrayList(IteratorsJVM.m703K(arrayList, 10));
        for (View view3 : arrayList) {
            arrayList4.add(Integer.valueOf(view3.getTop()));
        }
        Comparable a02 = _Collections.m687a0(arrayList4);
        MutabilityOwnership.m3747j(a02);
        this.f19725F = (float) ((Number) a02).intValue();
        ArrayList arrayList5 = new ArrayList(IteratorsJVM.m703K(arrayList, 10));
        for (View view4 : arrayList) {
            arrayList5.add(Integer.valueOf(view4.getBottom()));
        }
        Comparable Y2 = _Collections.m689Y(arrayList5);
        MutabilityOwnership.m3747j(Y2);
        this.f19726G = (float) ((Number) Y2).intValue();
    }

    public final void setDoubleTapZoom(float f) {
        this.f19737w = StringMerger.m2856f(f, this.f19736v, this.f19735u);
    }

    public final void setMaxZoom(float f) {
        this.f19735u = f;
        float f2 = this.f19733s;
        if (f2 > f) {
            m4452w(this, f2, 0.0f, 0.0f, 6);
        }
    }

    public final void setMinZoom(float f) {
        this.f19736v = f;
        if (this.f19733s < f) {
            m4452w(this, f, 0.0f, 0.0f, 6);
        }
    }

    @Override // android.view.View
    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.f19730K = onClickListener;
    }

    public final void setPanXEnabled(boolean z) {
        this.f19721B = z;
    }

    public final void setPanYEnabled(boolean z) {
        this.f19722C = z;
    }

    /* renamed from: t */
    public final float m4455t(float f, float f2) {
        float f3 = f2 - f;
        float signum = Math.abs(f3) > 0.5f ? (Math.signum(f3) * 0.5f) + f : f2;
        return C3149d.m6209a(f2, signum, 0.2f, signum);
    }

    /* renamed from: u */
    public final void m4454u(MotionEvent motionEvent) {
        float x = motionEvent.getX();
        float y = motionEvent.getY();
        if (this.f19734t == 1.0f) {
            if (!this.f19721B) {
                x = ((float) getWidth()) / 2.0f;
            }
            if (!this.f19722C) {
                y = ((float) getHeight()) / 2.0f;
            }
            m4453v(this.f19737w, StringMerger.m2856f(x, this.f19723D, this.f19724E), StringMerger.m2856f(y, this.f19725F, this.f19726G));
            return;
        }
        m4453v(1.0f, ((float) getWidth()) / 2.0f, ((float) getHeight()) / 2.0f);
    }

    /* renamed from: v */
    public final void m4453v(float f, float f2, float f3) {
        this.f19734t = StringMerger.m2856f(f, this.f19736v, this.f19735u);
        this.f19740z = f2;
        this.f19720A = f3;
        invalidate();
    }
}
